package com.baizhi.service.impl;

import com.baizhi.dao.StudentDao;
import com.baizhi.Subway;
import com.baizhi.service.SubwayService;
import com.baizhi.util.MyBatisUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class SubwayServiceImpl implements SubwayService {
    @Override
    public void insert(Subway c) {
        SqlSession session = MyBatisUtils.openSession();
        try {
            StudentDao mapper = session.getMapper(StudentDao.class);
            mapper.insert(c);
            session.commit();
        } catch (Exception e) {
            session.rollback();
            e.printStackTrace();
        } finally {
            MyBatisUtils.close(session);
        }
    }

    @Override
    public PageInfo<Subway> page(int pageIndex, int pageSize) {
        SqlSession session=MyBatisUtils.openSession();
        List<Subway> allStudent=null;
        try {
            PageHelper.startPage(pageIndex,pageSize);
            StudentDao mapper = session.getMapper(StudentDao.class);
            allStudent = mapper.selectList(null);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            MyBatisUtils.close(session);
        }
        PageInfo<Subway> pageInfo=new PageInfo<>(allStudent);
        return pageInfo;
    }
}
